<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns:ui="http://java.sun.com/jsf/facelets"
                template="../../Templates/SubFolderTemplate.xhtml"
                xmlns:p="http://primefaces.prime.com.tr/ui"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:f="http://java.sun.com/jsf/core">

    <ui:define name="content">
        <f:view beforePhase="#{viewSaleLeadsQuotations.initView}">
            <p:panel id="panel" header="View Sale Lead's Sale Quotations">
                <h:form prependId="false">
                    <p:dataTable id ="table1" var="saleQuotation" value="#{viewSaleLeadsQuotations.selectedSaleQuotations}" 
                                 selection ="#{viewSaleLeadsQuotations.selectedSaleQuotation}" onRowSelectUpdate="display"
                                 dynamic="true" paginator="true" rows="5" emptyMessage="No Sale Quotations" > 

                        <p:column selectionMode="single" />
                        <p:column sortBy="#{saleQuotation.id}" filterBy="#{saleQuotation.id}"> 
                                    <f:facet name="header"> 
                                        <h:outputText value="Sale Quotation ID" /> 
                                    </f:facet> 
                                    <h:outputText value="#{saleQuotation.id}" /> 
                        </p:column> 

                        <p:column sortBy="#{saleQuotation.saleInquiryDate}" filterBy="#{saleQuotation.saleInquiryDate}"> 
                            <f:facet name="header"> 
                                <h:outputText value="Date" /> 
                            </f:facet> 
                            <h:outputText value="#{saleQuotation.saleInquiryDate}" /> 
                        </p:column> 

                        <p:column sortBy="#{saleQuotation.saleLead.saleLeadName}"> 
                            <f:facet name="header"> 
                                <h:outputText value="Company Name" /> 
                            </f:facet> 
                            <h:outputText value="#{saleQuotation.saleLead.saleLeadName}" /> 
                        </p:column>

                        <p:column sortBy="#{saleQuotation.saleLead.registrationNumber}"> 
                            <f:facet name="header"> 
                                <h:outputText value="Registration Number" /> 
                            </f:facet> 
                            <h:outputText value="#{saleQuotation.saleLead.registrationNumber}" /> 
                        </p:column>
                        
                        <f:facet name="footer">                    
                            <p:commandButton value="View" image="ui-icon ui-icon-search" update="display1 display2" oncomplete="saleQuotationDialog.show()"/>
                            <p:commandButton value="Edit" image="ui-icon ui-icon-pencil" actionListener="#{viewSaleLeadsQuotations.editSaleQuotation(event)}">
                                <f:attribute name="selectedSaleQuotation" value="#{saleQuotation}"/>
                            </p:commandButton>  
                            <p:commandButton value="Delete" image="ui-icon ui-icon-trash" update="display3 display4" oncomplete="saleQuotationDeleteDialog.show()"  rendered="#{controller.CRMDeletable}"/>

                            <p:commandButton value="Convert" image="ui-icon ui-icon-arrowreturnthick-1-e" actionListener="#{viewSaleLeadsQuotations.createSaleOrder}">
                                <f:attribute name="selectedSaleQuotation" value="#{saleQuotation}"/>
                            </p:commandButton>
                        </f:facet>

                    </p:dataTable>
                    
                    
                    <p:dialog header="Sale Quotation Detail" widgetVar="saleQuotationDialog" resizable="true" 
                              width="600" showEffect="clip" hideEffect="fold">
                        <h:panelGrid id="display1" columns="2" cellpadding="4">
                            <h:outputText value="Sale Quotation ID:"/>
                            <h:outputText value="#{viewSaleLeadsQuotations.selectedSaleQuotation.id}"/>
                            
                            <h:outputText value="Created Date:"/>
                            <h:outputText value="#{viewSaleLeadsQuotations.selectedSaleQuotation.saleInquiryDate}"/>
                            
                            <h:outputText value="Validity Period:"/>
                            <h:outputText value="#{viewSaleLeadsQuotations.selectedSaleQuotation.validityPeriod} days"/>
                            
                            <h:outputText value="Expiry Date:"/>
                            <h:outputText value="#{viewSaleLeadsQuotations.selectedSaleQuotation.expiryDate}"/>
                            
                            <h:outputText value="Sale Lead Name:"/>
                            <h:outputText value="#{viewSaleLeadsQuotations.selectedSaleQuotation.saleLead.saleLeadName}"/>  
                            
                            <h:outputText value="Registration Number:"/>
                            <h:outputText value="#{viewSaleLeadsQuotations.selectedSaleQuotation.saleLead.registrationNumber}"/>
                            
                            <h:outputText value="Custom Discount:"/>
                            <h:outputText value="#{viewSaleLeadsQuotations.selectedSaleQuotation.customDiscount}"/>
                            
                               
                        </h:panelGrid>
                        
                        <p:dataTable var="lineItem" value="#{viewSaleLeadsQuotations.selectedSaleQuotation.lineItems}"
                                     dynamic="true" paginator="true" emptyMessage="No Product Type" id="display2">
                            <p:column sortBy="#{lineItem.productPrice.productType}">
                                <f:facet name="header">
                                    <h:outputText value="Type"/>
                                </f:facet>
                                <h:outputText value="#{lineItem.productPrice.productType}"/>
                            </p:column>

                            <p:column sortBy="#{lineItem.lineItemQuantity}">
                                <f:facet name="header">
                                    <h:outputText value="Quantity"/>
                                </f:facet>
                                <h:outputText value="#{lineItem.lineItemQuantity}"/>
                            </p:column>
                            
                            <p:column sortBy="#{lineItem.productPrice.productPrice}">
                                <f:facet name="header">
                                    <h:outputText value="Price per Unit"/>
                                </f:facet>
                                <h:outputText value="#{lineItem.productPrice.productPrice}"/>
                            </p:column> 
                            
                            <p:column sortBy="#{lineItem.volumeDiscountRate}">
                                <f:facet name="header">
                                    <h:outputText value="Volume Discount"/>
                                </f:facet>
                                <h:outputText value="#{lineItem.volumeDiscountRate}"/>
                            </p:column> 
                            
                            <p:column sortBy="#{lineItem.finalPrice}">
                            <f:facet name="header">
                                <h:outputText value="Final Price($)"/>
                            </f:facet>
                            <h:outputText value="#{lineItem.finalPrice}"/>
                        </p:column>
                            
                            <f:facet name="footer">
                                <h:outputText value ="Total Price: "/>
                                <h:outputText value ="#{viewSaleLeadsQuotations.selectedSaleQuotation.totalPrice}"/>
                            </f:facet>                          
                        </p:dataTable>                            
                    </p:dialog>
                    
                    
                    <p:dialog header="Sale Quotation Detail" widgetVar="saleQuotationDeleteDialog" width="600" height="400" resizable="true"
                              showEffect="explode" hideEffect="explode">
                        <h:panelGrid id="display3" columns="2" cellpadding="4">
                            <h:outputText value="Sale Quotation ID:"/>
                            <h:outputText value="#{viewSaleLeadsQuotations.selectedSaleQuotation.id}"/>
                            
                            <h:outputText value="Sale Quotation Date:"/>
                            <h:outputText value="#{viewSaleLeadsQuotations.selectedSaleQuotation.saleInquiryDate}"/>
                            
                            <h:outputText value="Sale Lead ID:"/>
                            <h:outputText value="#{viewSaleLeadsQuotations.selectedSaleQuotation.saleLead.registrationNumber}"/>
                            
                            <h:outputText value="Sale Lead Name:"/>
                            <h:outputText value="#{viewSaleLeadsQuotations.selectedSaleQuotation.saleLead.saleLeadName}"/>                           
                        </h:panelGrid>
                        
                        <p:dataTable var="lineItem" value="#{viewSaleLeadsQuotations.selectedSaleQuotation.lineItems}"
                                     dynamic="true" paginator="true" emptyMessage="No Product Type" id="display4">
                            <p:column sortBy="#{lineItem.product.productType}">
                                <f:facet name="header">
                                    <h:outputText value="Product Type"/>
                                </f:facet>
                                <h:outputText value="#{lineItem.productPrice.productType}"/>
                            </p:column>

                            <p:column sortBy="#{lineItem.productPrice.productPrice}">
                                <f:facet name="header">
                                    <h:outputText value="Price"/>
                                </f:facet>
                                <h:outputText value="#{lineItem.productPrice.productPrice}"/>
                            </p:column> 
                            
                            <p:column sortBy="#{lineItem.lineItemQuantity}">
                                <f:facet name="header">
                                    <h:outputText value="Quantity"/>
                                </f:facet>
                                <h:outputText value="#{lineItem.lineItemQuantity}"/>
                            </p:column>
                        
                            <p:column sortBy="#{lineItem.finalPrice}">
                                <f:facet name="header">
                                    <h:outputText value="Discount Price"/>
                                </f:facet>
                                <h:outputText value="#{lineItem.finalPrice}"/>
                            </p:column> 
                            
                            <f:facet name="footer">
                                <h:outputText value ="Total Price: "/>
                                <h:outputText value ="#{viewSaleLeadsQuotations.selectedSaleQuotation.totalPrice}"/>
                            </f:facet> 
                        </p:dataTable> 
                        
                        <p:spacer height="35"/>
                        <p:commandButton value="Confirm Delete" image="ui-icon ui-icon-trash" actionListener="#{viewSaleLeadsQuotations.deleteSaleQuotation}" oncomplete="saleQuotationDeleteDialog.hide()">
                            <f:attribute name="selectedSaleQuotation" value="#{saleQuotation}"/>
                        </p:commandButton>
                        <p:commandButton value="Cancel" image="ui-icon ui-icon-close" onclick="saleQuotationDeleteDialog.hide()" type="button"/>
                        <p:messages />
                        
                    </p:dialog>
                </h:form>
            </p:panel>
        </f:view>
    </ui:define>
</ui:composition>
